package hu.u_szeged.inf.ovrt.ioc_demo.controller;

import hu.u_szeged.inf.ovrt.ioc_demo.beans.User;
import hu.u_szeged.inf.ovrt.ioc_demo.dao.UserDAO;
import hu.u_szeged.inf.ovrt.ioc_demo.ui.UI;

public class SimpleController implements Controller {
    private UI ui;
    private UserDAO dao;
    
    public SimpleController() {}
    
    public SimpleController(UI ui, UserDAO dao) {
        this.ui = ui;
        this.dao = dao;
    }

    @Override
    public void run() {
        ui.print("Controller started!");
        ui.newLine();
        
        ui.print("User(3):");
        printUser("3");
        ui.newLine();
        
        ui.print("UserList:");
        printAllUser();
        ui.newLine();
        
        ui.print("Controller stopped!");
    }
    
    private void printAllUser() {
        for (User user : dao.getUsers()) {
            ui.print(user);
        }
    }
    
    private void printUser(String userID) {
        User user = dao.getUserByID(userID);
        if(user !=null) {
            ui.print(user);
        } else {
            ui.print("User not found!");
        }
    }
    
    public void setUi(UI ui) {
        this.ui = ui;
    }
    
    public void setDao(UserDAO dao) {
        this.dao = dao;
    }
}
